<template>
    <div class="form-all">
        <div class="form-wrapper">
            <div class="form-logo">
                <img src="../assets/petLogo.png" alt="">
            </div>
            <div class="header">OnePet后台管理</div>
            <div class="input-wrapper">
                <div class="border-wrapper">
                    <input type="text" v-model="admin" name="username" placeholder="请输入管理员账户" class="border-item"
                        autocomplete="off" @keyup.enter="login" />
                </div>
                <div class="border-wrapper">
                    <input type="password" v-model="password" name="password" placeholder="请输入密码" class="border-item"
                        autocomplete="off" @keyup.enter="login" />
                </div>
            </div>
            <div class="action">
                <div class="btn" @click="login">登录</div>
            </div>
            <div class="icon-wrapper">
                <i class="el-icon-edit"></i>
                <i class="el-icon-chat-dot-round"></i>
                <i class="el-icon-mobile-phone"></i>
            </div>
        </div>
    </div>
</template>
<script>

export default {
    computed: {

    },
    data() {
        return {
            admin: "",
            password: ""
        }
    },
    methods: {
        login() {
            if (this.admin.length == 0) {
                this.$message.error("账号不能为空")
                return
            }
            if (this.password.length == 0) {
                this.$message.error("密码不能为空")
                return
            }
            // const params = `d_admin=${this.admin}&&d_pwd=${this.password}`
            const data = {
                d_admin: this.admin,
                d_pwd: this.password
            }
            this.$axios.post(this.$api.login, data).then(res => {
                if (res?.data?.code === 200) {
                    // 将token存到sessionStorage
                    sessionStorage.setItem("token", res?.data?.data?.token)
                    // 将用户信息保存到sessionStorage
                    sessionStorage.setItem("admin", JSON.stringify(res?.data?.data))
                    this.$message.success(res?.data?.msg)
                    // 跳转到主界面
                    this.$router.replace("/home")
                } else {
                    this.$message.error(res?.data?.msg)
                }
                // // token失效处理
                // if (res?.code === 202) {
                //     this.$router.replace("/login")
                //     this.$message.error(res.msg)
                // }
            }).catch(err => {
                console.log("失败", err);
            })
        }
    },
}
</script>
<style>
body {
    background: url("../assets/banner.jpg");
    background-position: right top;
}

.form-all {
    height: 100%;
    width: 100%;
    font-family: JetBrains Mono Medium;
    display: flex;
    align-items: center;
    justify-content: center;
    /* background-color: #0e92b3; */
    /* background-color: #545765; */
    background-size: 100% 100%;
}

.form-wrapper .form-logo img {
    width: 100%;
}

.form-wrapper {
    width: 300px;
    background-color: rgba(41, 45, 62, 0.5);
    color: #fff;
    border-radius: 15px;
    padding: 50px;
}

.form-wrapper .header {
    text-align: center;
    font-size: 35px;
    /* text-transform: uppercase; */
    line-height: 100px;
    background-image: linear-gradient(to right, #e8198b, #0eb4dd);
    background-clip: text;
    color: transparent;
}

.form-wrapper .input-wrapper input {
    background-color: rgb(41, 45, 62);
    border: 0;
    width: 100%;
    text-align: center;
    /* padding-left: 15px; */
    text-indent: 15px;
    font-size: 15px;
    color: #fff;
    outline: none;
}

.form-wrapper .input-wrapper input::placeholder {
    text-transform: uppercase;
}

.form-wrapper .input-wrapper .border-wrapper {
    background-image: linear-gradient(to right, #e8198b, #0eb4dd);
    width: 100%;
    height: 50px;
    margin-bottom: 20px;
    border-radius: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.form-wrapper .input-wrapper .border-wrapper .border-item {
    height: calc(100% - 4px);
    width: calc(100% - 4px);
    border-radius: 30px;
}

.form-wrapper .action {
    display: flex;
    justify-content: center;
}

.form-wrapper .action .btn {
    width: 60%;
    text-transform: uppercase;
    border: 2px solid #0e92b3;
    text-align: center;
    line-height: 50px;
    border-radius: 30px;
    cursor: pointer;
    user-select: none;
}

.form-wrapper .action .btn:active {
    background-image: linear-gradient(120deg, #84fab0 0%, #8fd3f4 100%);
}

.form-wrapper .icon-wrapper {
    text-align: center;
    width: 60%;
    margin: 0 auto;
    margin-top: 20px;
    border-top: 1px dashed rgb(146, 146, 146);
    padding: 20px;
}

.form-wrapper .icon-wrapper i {
    font-size: 20px;
    color: rgb(187, 187, 187);
    cursor: pointer;
    border: 1px solid #fff;
    padding: 5px;
    border-radius: 20px;
    margin: 3px;
}

.form-wrapper .icon-wrapper i:hover {
    background-color: #0e92b3;
}
</style>